package com.zhj.agent.interceptor.doubbo;

import com.zhj.agent.support.AbstractClassEnhancePluginDefine;
import com.zhj.agent.support.InstanceMethodsInterceptPoint;

import net.bytebuddy.description.method.MethodDescription;
import net.bytebuddy.matcher.ElementMatcher;

import static net.bytebuddy.matcher.ElementMatchers.named;

/**
 * dubbo插件
 */
public class DubboInstrumentation extends AbstractClassEnhancePluginDefine {
    private static final String ENHANCE_CLASS = "org.apache.dubbo.monitor.support.MonitorFilter";

    private static final Class<DubboInterceptor> INTERCEPT_CLASS = DubboInterceptor.class;

    /** DO_EXECUTE_METHOD_NAME */
    private static final String INVOKE_METHOD_NAME = "invoke";

    public DubboInstrumentation() {
        super(ENHANCE_CLASS);
    }

    @Override
    public InstanceMethodsInterceptPoint[] enhanceInstance() {
        return new InstanceMethodsInterceptPoint[] {
            new InstanceMethodsInterceptPoint() {
                @Override
                public ElementMatcher<MethodDescription> getMethodsMatcher() {

                    return named(INVOKE_METHOD_NAME);
                }

                @Override
                public Class<DubboInterceptor> getMethodsInterceptor() {
                    return INTERCEPT_CLASS;
                }

                @Override
                public boolean isOverrideArgs() {
                    return false;
                }
            }
        };
    }
}
